{extend name="public/base" /}

{block name="title"}控制台{/block}

{block name="main"}
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <fieldset class="layui-elem-field site-demo-button" style="margin-top: 30px;border:0">
                <div class="layui-btn-group demoTable">
                    <a href="javascript:;" class="layui-btn layui-btn-sm save-category" data-id="0">新增分类</a>
                </div>
            </fieldset>
            <div class="layui-card">
                <div class="layui-card-header">分类列表</div>
                <div class="layui-card-body">
                    <table class="layui-table">
                        <colgroup>
                            <col width="100">
                            <col width="450">
                            <col width="150">
                            <col>
                        </colgroup>
                        <thead>
                        <tr>
                            <th>ID</th>
                            <th>名称</th>
                            <th>图片</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        {empty name="data"}
                        <tr>
                            <td colspan="5" style="text-align: center">无数据</td>
                        </tr>
                        {else /}
                        {volist name="data" id="vo"}
                        <tr>
                            <td>{$vo.id}</td>
                            <td>{:str_repeat('&nbsp;&nbsp;&nbsp;', $vo.level * 2)}{$vo.name}</td>
                            <td><img class="layui-upload-img logo" src="{$vo.image|default=''}"></td>
                            <td>
                                <a class="layui-btn layui-btn-sm save-category" data-id="{$vo.id}">编辑</a>
                                <a class="layui-btn layui-btn-sm">删除</a>
                            </td>
                        </tr>
                        {/volist}
                        {/empty}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
{/block}

{block name="js"}
<script>
    layui.use(['index', 'layer'], function(){
        var $ = layui.jquery, layer = layui.layer;

        $(".save-category").click(function () {
            var _this = $(this);
            var _id = _this.data('id');
            layer.open({
                type: 2,
                title: (_id == 0 ? '新增' : '编辑') + '分类',
                shadeClose: true,
                shade: 0.8,
                area: ['100%', '100%'],
                content: '/admin/category/save_category/id/' +  _id  //iframe的url
            });
        });
    });
</script>
{/block}